import { createRouter, createWebHashHistory } from "vue-router";
import {getSessionStorage} from "../common.js";

const routes = [
    {
        path: "/",
        redirect:"/login",
    },
    {
        path:"/customerindex",
        name:"customerindex",
        component: ()=>import("../views/CustomerIndex.vue"),
    },{
        path:"/businessindex",
        name:"businessindex",
        component: ()=>import("../views/BusinessIndex.vue"),
    },{
        path: "/login",
        name:"login",
        component: ()=>import("../views/Login.vue"),
        meta: {
            keepAlive: false,
        }
    },{
        path: "/register",
        name:"register",
        component: ()=>import("../views/Register.vue"),
        meta: {
            keepAlive: false,
        }
    },{
        path:"/order",
        name:"order",
        component: ()=>import("../views/Order.vue"),
        meta: {
            keepAlive: false,
        }
    },{
        path:"/my",
        name:"my",
        component: ()=>import("../views/My.vue"),
        meta: {
            keepAlive: false,
        }
    },{
        path:"/shopItemList/:shopId",
        name:"businessInfo",
        component: ()=>import("../views/Shop.vue"),
        meta: {
            keepAlive: false,
        }
    },{
        path:"/confirmOrder",
        name:"confirmOrder",
        component: ()=>import("../views/confirmOrder.vue"),
        meta: {
            keepAlive: true,
        }
    },{
        path:"/payment/:orderId",
        name:"payment",
        component: ()=>import("../views/Payment.vue"),
        meta: {
            keepAlive: false,
        }
    },{
        path:"/businessShopItemList/:shopId",
        name:"businessShopItemList",
        component: ()=>import("../views/BusinessShopItemList.vue"),
        meta: {
            keepAlive: false,
        }
    },{
        path:"/businessShopOrders/:shopId",
        name:"businessShopOrders",
        component: ()=>import("../views/BusinessShopOrders.vue"),
        // children:[
        //     {
        //         path:"allOrders",
        //         name:"allOrders",
        //         component:()=>import("../components/BusinessShopOrdersItem.vue"),
        //         props: route => ({ key: route.fullPath }) ,// 使用路由的 fullPath 作为 key,以便创建不同实例,
        //     },{
        //         path:"confirmOrders",
        //         name:"confirmOrders",
        //         component:()=>import("../components/BusinessShopOrdersItem.vue"),
        //         props: route => ({ key: route.fullPath }),
        //     },{
        //         path:"refundOrders",
        //         name:"refundOrders",
        //         component:()=>import("../components/BusinessShopOrdersItem.vue"),
        //         props: route => ({ key: route.fullPath }),
        //     }
        // ]
    }
]



const router = createRouter({
    history: createWebHashHistory(),
    routes
});
router.beforeEach(function(to,from,next){
    let user = getSessionStorage("user");
    //除了登录、注册、首页、商家列表、商家信息之外，都需要判断是否登录
    if(!(to.path==='/'||to.path==='/index'||to.path==='/businessList'||to.path==='/businessInfo'||to.path==='/login'||to.path==='/register')){
            if(user==null){
                router.push('/login');
                location.reload();
            }
}
    next();
});
export default router;